﻿using System;
using EasyCommonCore.Common;

namespace ABlog.Domain.Infrastructure
{
    /// <summary>
    /// 友好异常,可以将hint消息直接返回给用户
    /// </summary>
    public class FriendlyException : Exception
    {
        /// <summary>
        /// 友好异常,可以将hint消息直接返回给用户
        /// </summary>
        /// <param name="hint">返回给用户友好的异常</param>
        /// <param name="err">错误信息</param>
        public FriendlyException(string hint, string err)
            : base(new { Hint = hint, Err = err }.ToJson())
        {

        }
    }

    /// <summary>
    /// 业务异常,可以将Exception消息直接返回给用户
    /// </summary>
    public class BusinessException : Exception
    {
        /// <summary>
        /// 业务异常
        /// </summary>
        /// <param name="hint">业务异常</param>
        public BusinessException(string hint)
            : base(hint)
        {

        }
    }

    /// <summary>
    /// 重复请求
    /// </summary>
    public class RepeatRequestException : Exception
    {
        public RepeatRequestException(string message)
            : base(message)
        {

        }
    }

    /// <summary>
    /// 身份认证失败,需要重新登陆
    /// </summary>
    public class AuthException : Exception
    {
        public AuthException(string message)
            : base(message)
        {

        }
    }

    /// <summary>
    /// 数据库信息异常
    /// </summary>
    public class DbException : Exception
    {
        public DbException(string message)
            : base(message)
        {

        }
    }

    /// <summary>
    /// 消息队列异常
    /// </summary>
    public class QueueException : Exception
    {
        public QueueException(string message)
            : base(message)
        {

        }

        /// <summary>
        /// Rabbit信息
        /// </summary>
        public string RabbitInfo { get; set; }

        /// <summary>
        /// 消息队列名称
        /// </summary>
        public string QueueName { get; set; }

        /// <summary>
        /// 当前消息
        /// </summary>
        public string CurrentMessage { get; set; }

        public override string ToString()
        {
            return "Exception" + Message + "RabbitInfo:" + RabbitInfo + ",QueueName:" + QueueName + ",CurrentMessage:" + CurrentMessage;
        }
    }
}